package mx.forms;

import org.w3c.dom.Document;

import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.stage.Modality;
import javafx.stage.Stage;

public class WebForm {
	private boolean modal = false;
	private int width = 900;
	private int height = 600;
	private String titile = "web form";
	private String url = null;
	
	protected Scene scene = null;
	
	public boolean isModal() {
		return modal;
	}

	public void setModal(boolean isModal) {
		this.modal = isModal;
	}

	public int getWidth() {
		return width;
	}

	public void setWidth(int width) {
		this.width = width;
	}

	public int getHeight() {
		return height;
	}

	public void setHeight(int height) {
		this.height = height;
	}

	public String getTitile() {
		return titile;
	}

	public void setTitile(String titile) {
		this.titile = titile;
	}

	protected final Stage stage = new Stage();
	protected final Browser browser = new Browser();  
	
	public void init() throws Exception {	
        scene = new Scene(browser, width, height);  
		stage.setScene(scene);		
		
		if (modal) {
			stage.initModality(Modality.APPLICATION_MODAL);
		}
		
		if (null != this.url) {
			//System.out.println("url="+url);
			this.loadUrl(this.url);
		}
	}
	
	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public Scene getScene() {
		return this.scene;
	}
	
	public void show() {
		stage.show();
	}
	
	public void hide() {
		stage.hide();
	}
	
	public void loadUrl(String u) {
		this.browser.loadUrl(u);
	}
	
	public void loadContent(String content) {
		this.browser.loadContent(content);
	}
	
	public Document getDocument() throws Exception {
		return this.browser.webEngine.getDocument();
	}
}
